package genetic.q3;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

public class SRFileReader {

	public double[][] readFile(String file) {
		File f = new File(file);
		try {
			BufferedReader in = new BufferedReader(new FileReader(f));
			Vector<double[]> pointsVector = new Vector<double[]>();
			
			String s = null;
			while (( s = in.readLine()) != null){
				String[] pts = s.split("  ");
				double x = Double.parseDouble(pts[0]);
				double y = Double.parseDouble(pts[1]);
				pointsVector.add(new double[]{x, y});
			}
			double[][] ans = new double[pointsVector.size()][2];
			int index = 0;
			for (double[] tmp: pointsVector){
				ans[index] = tmp;
				index++;
			}
			return ans;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
